package com.youwe.util.serializable;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

@SuppressWarnings("all")
public class JSONUtils {

	private static ObjectMapper objectMapper = new ObjectMapper();

	public static String mapToJson(Map map){
		try {
			return objectMapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		}
	}
	
	public static String modelToJson(Object model){
		try {
			return objectMapper.writeValueAsString(model);
		} catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		}
	}

	public static Map jsontToMap(String json){
		try {
			return objectMapper.readValue(json, Map.class);
		} catch (Exception e) {
			throw new RuntimeException(e);
		} 
	}

	public static <T> T jsonToModel(String json, Class<T> t){
		try {
			return objectMapper.readValue(json,t);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}
